package cn.edu.hqu.cst.activity3;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity
        implements View.OnClickListener {
    TextView show;
    Button bn;
    @BindView(R.id.show)
    TextView Show;
    @BindView(R.id.bn6)
    Button bn6;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        show = (TextView) findViewById(R.id.show);
        bn = (Button) findViewById(R.id.bn2);
        bn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                show.setText("点击了匿名内部类的监听器");
            }
        });
        bn = (Button) findViewById(R.id.bn1);
        bn.setOnClickListener(this);
        bn = (Button) findViewById(R.id.bn4);
        bn.setOnClickListener(new MyClickListener());
        Button bn8 = (Button) findViewById(R.id.bn8);
        bn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, bn8.class);
                startActivity(i);
            }
        });
        Button bn7 = (Button) findViewById(R.id.bn7);
        bn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, bn7.class);
                startActivity(i);
            }
        });
        bn = (Button) findViewById(R.id.bn5);
        bn.setOnClickListener(new OutButton());
    }

    @Override
    public void onClick(View v) {
        show.setText("点击了Activity作为监听器");
    }

    @OnClick({R.id.show, R.id.bn6})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.show:
                break;
            case R.id.bn6:
                break;
        }
    }

    class MyClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            TextView show = (TextView) findViewById(R.id.show);
            show.setText("点击了内部类的监听器");
        }
    }

    public void clickHandler(View source) {
        TextView show = (TextView) findViewById(R.id.show);
        show.setText("点击了绑定到标签的监听器");
    }

    public class OutButton implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            TextView show = (TextView) findViewById(R.id.show);
            show.setText("点击了外部类的监听器");
        }
    }
}
